from google.appengine.ext import db


class HistoryUsers(db.Model):
    tuser = db.UserProperty()
    history = db.ListProperty(float)

class TrendUsers(db.Model):
    tuser = db.UserProperty()
    bankamount = db.FloatProperty()
    totalamount = db.FloatProperty(default=0.0)
    lastweekamount = db.FloatProperty(default=0.0)
    lastweekprcnt = db.FloatProperty(default=1.0)
    complist = db.ListProperty(db.Key)
    alert = db.FloatProperty(default=0.0)    
    joindate = db.DateTimeProperty(auto_now_add=True)
    userPrecentChangeDaily=db.FloatProperty(default=1.0)
    cronupdatedate = db.DateProperty(auto_now_add=True)
    yahooPhase = db.IntegerProperty(default=0)
    isAdvertiser=db.BooleanProperty(default=False)
    realMoney = db.FloatProperty(default=0.0)

class StocksCategories(db.Model):
    category = db.StringProperty(multiline=True)
        
class StocksData(db.Model):
    stockname = db.StringProperty(multiline=True)
    categoryref = db.ReferenceProperty(StocksCategories)
    stockcounter= db.IntegerProperty(default=0)
    arenacounter= db.IntegerProperty(default=0)
    precentChange=db.FloatProperty(default=1.0)
    yahooValue=db.FloatProperty(default=0.0)
    yahooPercentChange=db.FloatProperty(default=1.0)
    yahooPhase=db.IntegerProperty(default=0)
    stockIcon=db.BlobProperty()
    last30Days=db.ListProperty(float)
    relatedSearches=db.ListProperty(str)
    topRegions=db.ListProperty(str)
    MonthChange=db.FloatProperty()
    FifteenDaysChange=db.FloatProperty()
    isProfile = db.BooleanProperty(default=False)
    updatedate = db.DateTimeProperty()
    yahooupdatedate = db.DateTimeProperty()
    cronupdatedate = db.DateProperty(auto_now_add=True)
    seasonalityUpdateDate=db.DateProperty(auto_now_add=True)

class ETFData(db.Model):
    categoryref = db.ReferenceProperty(StocksCategories)
    stocklist= db.ListProperty(db.Key)
    precentChange=db.FloatProperty(default=1.0)
    updatedate=db.DateTimeProperty()
    isProfile = db.BooleanProperty(default=False)
    cronupdatedate = db.DateProperty(auto_now_add=True)
    
class Stocks(db.Model):
    buyer = db.UserProperty()
    buyValue = db.FloatProperty()
    currValue = db.FloatProperty()
    currValueNotRounded = db.FloatProperty()
    currValueBase=db.FloatProperty()
    buydate = db.DateTimeProperty(auto_now_add=True)
    stockref = db.ReferenceProperty(StocksData)
    basketref=db.ReferenceProperty(ETFData)
    categoryref = db.ReferenceProperty(StocksCategories)        
    userPrecentChange=db.FloatProperty(default=1.0)
    yahooupdatedate=db.DateTimeProperty()
    userupdatedate=db.DateTimeProperty()


class NewsFeeds(db.Model):
    buyer = db.UserProperty()
    buyValue = db.FloatProperty()
    currValue = db.FloatProperty()
    buydate = db.DateTimeProperty(auto_now_add=True)
    actiondate = db.DateTimeProperty(auto_now_add=True)
    stockname = db.StringProperty()
    stockETF = db.IntegerProperty(default=0)
    flag =    db.IntegerProperty(default=0)
    stockref = db.ReferenceProperty(StocksData)
    etfref = db.ReferenceProperty(ETFData)

    
class CronJ(db.Model):
    rundate=db.DateProperty(auto_now_add=True)
    phase=db.IntegerProperty(default=0)
    
class Competition(db.Model):
    password = db.StringProperty()
    members = db.ListProperty(db.Key)
    membersAmount = db.ListProperty(float)
    arenaKeywords = db.BlobProperty()
    membersChoice = db.ListProperty(int)
    compKeywordsAmount = db.ListProperty(float)
    startdate = db.DateProperty()
    enddate = db.DateProperty()
    compamount = db.IntegerProperty()
    advamount = db.IntegerProperty()
    public = db.BooleanProperty()
    title= db.StringProperty()
    status=db.IntegerProperty(default=0)
    type=db.IntegerProperty()
    owner=db.UserProperty()
    isAd=db.BooleanProperty(default=False)

class Comment(db.Model):
    commentkey = db.ReferenceProperty(Competition)
    userref = db.UserProperty()
    usernick = db.StringProperty()
    commenttext = db.StringProperty(multiline=True)
    created_date = db.DateTimeProperty(auto_now_add=True)
    
class YahooCronJ(db.Model):
    runhour = db.DateTimeProperty(auto_now_add=True)
    phase = db.IntegerProperty(default=1)